//
//  RefreshView.swift
//  GitWeibo
//
//  Created by 胡金东 on 2017/6/14.
//  Copyright © 2017年 胡金东. All rights reserved.
//

import UIKit

class RefreshView: UIView {
    /// - 系统UIView 封装的旋转动画
    /// - 默认顺时针旋转
    /// - 就近原则，所以加一个0.001类似的小值
    /// - 刷新状态
    var refreshStatus :RefreshStatus = .normal {
        didSet{
            switch refreshStatus {
            case .normal:
                /// - 正常时候显示图标
                tipIcom?.isHidden = false
                /// - 结束菊花动画
                indicator?.stopAnimating()
       
                
                tipLbl?.text = "继续使劲拉..."
                
                UIView.animate(withDuration: 0.25, animations: {
                    /// - 恢复原状
                   self.tipIcom?.transform = CGAffineTransform.identity
                })
            case .pulling:
                tipLbl?.text = "放手就刷新..."
                UIView.animate(withDuration: 0.25, animations: {
                    /// - 旋转180
                    self.tipIcom?.transform = CGAffineTransform.init(rotationAngle: CGFloat(M_PI + 0.001))
                })
            case .willRefresh:
                tipLbl?.text = "正在刷新中..."
                /// - 隐藏提示图标
                tipIcom?.isHidden = true
            
                /// - 开始菊花动画
                indicator?.startAnimating()
                
//            default: break
                
            }
        }
    }
    
    /// - 父视图的高度 - 为了刷新控件，不需要关心当前具体的刷新视图是谁
    var parentViewheight: CGFloat = 0
    
     /// - 刷新指示器
    @IBOutlet var indicator: UIActivityIndicatorView?
     /// - 刷新提示图标
    @IBOutlet var tipIcom: UIImageView?
    /// - 刷新提示标签
    @IBOutlet var tipLbl: UILabel?
    
    
    class func refreshView() -> RefreshView {
        
//        let nib = UINib(nibName: "RefreshView", bundle: nil)
        
//        let nib = UINib(nibName: "HeroRefreshView", bundle: nil)
        let nib = UINib(nibName: "meituanRefreshView", bundle: nil)
        
        return nib.instantiate(withOwner: nil, options: nil)[0] as! RefreshView
        
    }
    
}
